package com.ruoyi.account.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Getter
public enum AccountTypeEnum {

    CHAN("CHAN", "渠道", false, 1L),
    PROD("PROD", "产品", false, 1L),
    SPECIAL("SPECIAL", "机构", true, 6L),
    FORM("FORM", "表单", false, 1L),
    ACCOUNT("ACCOUNT", "总账户", true, 5L),
    ;

    String value;
    String name;
    boolean showFlag;
    Long postId;// 岗位ID

    AccountTypeEnum(String value, String name, boolean showFlag, Long postId){
        this.value = value;
        this.name = name;
        this.showFlag = showFlag;
        this.postId = postId;
    }

    public String getValue() {
        return this.value;
    }

    public String getLabel() {
        return this.name;
    }

    public static String getLabelByValue(String value) {
        for (AccountTypeEnum accountTypeEnum : values()) {
            if (StrUtil.equals(accountTypeEnum.getValue(), value)){
                return accountTypeEnum.getLabel();
            }
        }
        return value;
    }

    public AccountTypeEnum getEntryByValue(String value) {
        for (AccountTypeEnum accountTypeEnum : values()) {
            if (StrUtil.equals(accountTypeEnum.getValue(), value)){
                return accountTypeEnum;
            }
        }
        return null;
    }

    public static List<Map<String, String>> getListMapByPostId(List<Long> postIdList) {
        List<Map<String, String>> listMap = new ArrayList<>();
        for (AccountTypeEnum item : values()) {
            if (postIdList.contains(item.getPostId())){
                Map<String, String> itemMap = new HashMap<>();
                itemMap.put("name", item.getName());
                itemMap.put("value", item.getValue());
                listMap.add(itemMap);
            }
        }
        return listMap;
    }

    public static List<Map<String, String>> getListMap() {
        List<Map<String, String>> listMap = new ArrayList<>();
        for (AccountTypeEnum item : values()) {
            if (item.isShowFlag()){
                Map<String, String> itemMap = new HashMap<>();
                itemMap.put("name", item.getName());
                itemMap.put("value", item.getValue());
                listMap.add(itemMap);
            }
        }
        return listMap;
    }
}
